***********************************************************************************************************************************************************************
***Analyses for the article "RATIO BIAS AND POLICY PREFERENCES: HOW EQUIVALENCY FRAMING OF NUMBERS CAN AFFECT ATTITUDES" Published in Political Psychology*************
***********************************************************************************************************************************************************************
***Written for STATA 14 ***********************************************************************************************************************************************
***********************************************************************************************************************************************************************

*************************
***Setting up the data***
*************************
clear all
set more off
cd "C:\Ratio_bias_and_policy_preferences"
use "C:\Ratio_bias_and_policy_preferences\Ratio_bias_and_policy_preferences_main_exp.dta", clear

***Destringing variable/values***
replace q4="0" if q4=="0 Venstre"
replace q4="10" if q4=="10 Højre"
replace q4="99" if q4=="Ved ikke"
destring q4, replace

replace q6a="0" if q6a=="0 Forskellen er meget lille" //these variables are all for a subsequent experiment, that is not relevant for this paper
replace q6a="10" if q6a=="10 Forskellen er meget stor"
destring q6a, replace
replace q6b="0" if q6b=="0 Forskellen er meget lille"
replace q6b="10" if q6b=="10 Forskellen er meget stor"
destring q6b, replace
replace q6c="0" if q6c=="0 Forskellen er meget lille"
replace q6c="10" if q6c=="10 Forskellen er meget stor"
destring q6c, replace
replace q6d="0" if q6d=="0 Forskellen er meget lille"
replace q6d="10" if q6d=="10 Forskellen er meget stor"
destring q6d, replace
replace q7="0" if q7=="0 Bør sættes meget ned"
replace q7="10" if q7=="10 Bør sættes meget op"
replace q7="99" if q7=="Ved ikke"
destring q7, replace


foreach var of varlist q2_1 q2_2 q2_3 q2_4 q3 q5a q5b q5c q5d q8a q8b q8c q8d q9a q9b q9c q9d gender age_grp region urban FamilyLifeCycle education  {
encode `var', gen(temp`var')
drop `var'
clonevar `var'=temp`var'
drop temp`var'
}

drop q6a q6b q6c q6d q9a q9b q9c q9d page_q6a_timing page_q6b_timing page_q6c_timing page_q6d_timing _merge //dropping these variables from other, subsequent experiment

**************
***RECODING***
**************

***Time variables***
*q5*
 gen timeq5=max(page_q5a_timing, page_q5b_timing, page_q5c_timing, page_q5d_timing)
 egen slowtimeq5=cut(timeq5), group(2)
 egen rank_timeq5=rank(timeq5)
*total*
 egen slowtimetotal=cut(sekunder), group(2)
 egen rank_timetotal=rank(sekunder)

***Gender***
label define genders 1 "Women" 2 "Men"
label values gender genders
recode gender (1=1) (2=0), gen(female)

***Age***
rename age_grp age_grp_YouGov
recode age (18/29=1 "18-29") (30/45=2 "35-45") (46/59=3 "46-59") (60/99=4 "60+"), gen(age_group) //to ensure comparability with other study, I use other age groups than Yougov 

***Numeracy***
tab1 q2_1 q2_2 q2_3 q2_4 /* this line is to find the number of "don't know" answers*/
recode q2_1 q2_2 q2_3 q2_4(7=.) /* setting "don't know" */
misstable patterns q2_1 q2_2 q2_3 q2_4 if sekunder!=., freq
alpha q2_1 q2_2 q2_3 q2_4, item gen(numeracy_unstandardized)
	gen numeracy_unstandardized2=numeracy_unstandardized^2 //values are squared because of negative skew
	egen num_min=min(numeracy_unstandardized2) //the lines standardize the measure to 0-1
	egen num_max=max(numeracy_unstandardized2)
	gen numeracy= (numeracy_unstandardized2 - num_min)/(num_max-num_min)
	drop num_min num_max
	sum numeracy, detail
	
	egen highnumeracy=cut(numeracy), group(2) //median split numeracy variable used for ease of interpretation and checks. Not used in final article
	label define highnumeracy 0 "Low Numeracy" 1 "High Numeracy"
	label values highnumeracy highnumeracy
	

***Political Predisposition

*Party and party block*
recode q3 (2 10/12=.), gen(parties9)
recode parties9 (4 6 7 8 9  =1) (.=.) (else=0), gen(blue)
recode parties9 (1 3 5 13 =1)   (.=.) (else=0), gen(red)
label define lr 0 "Blue" 1 "Red"
label values red lr

*Left-Center*
recode q4 (99=.), gen(LR_unstandardized) /*ranges from 0 to 10 */
gen LR=LR_unstandardized/10

*Combining LR and Party*
by q3, sort: egen partyplace_median_u= median(LR) 
replace partyplace_median_u=. if LR!=. & parties9==. 
	egen partyplace_median_min=min(partyplace_median_u) //the lines standardize the measure to 0-1
	egen partyplace_median_max=max(partyplace_median_u)
	gen partyplace_median=(partyplace_median_u - partyplace_median_min)/(partyplace_median_max-partyplace_median_min)
	drop partyplace_median_min partyplace_median_max
alpha partyplace_median LR, gen(LR_with_party_median) item min(1)
	
***Education***
label define education_lbl 1 "High School" 2 "Vocational" 3 "High School 2" 4 "PhD" 5 "Primary" 6 "Short Tertiary" 7 "Medium Tertiary" 8 "Long Tertiary"
label values education education_lbl
recode education (1 3 5=1 "High School or less") (2=2 "Vocational") (4 6 7 8=3 "Some College"), gen(education_category)

***Stimuli***
recode q5a q5b q5c q5d (1=0) (2=1)
label define taxincrease 0 "Prefer status quo" 1 "Prefer taxincrease"
label values q5a q5b q5c q5d taxincrease
gen taxincrease=max(q5a, q5b, q5c, q5d)

gen taxincreasesplit=0
recode taxincreasesplit (0=1) if q5a!=.
recode taxincreasesplit (0=2) if q5b!=.
recode taxincreasesplit (0=3) if q5c!=.
recode taxincreasesplit (0=4) if q5d!=.
recode taxincreasesplit (0=.)
label define splitlabels 1 "LD-tax/SD-youths" 2 "SD-tax/SD-youths" 3 "LD-tax/LS-youths" 4 "SD-tax/LD-youths"
label values taxincreasesplit splitlabels

recode taxincreasesplit (1 2=0)(3 4=1), gen(q5largedeno_people) 
label define q5_people 0 "'7/100'" 1"'4,900/70,000'"
label values q5largedeno_people q5_people

recode taxincreasesplit (2 4=0)(1 3=1), gen(q5largedeno_tax)
recode q5largedeno_tax (1=0) (0=1), gen(q5smalldeno_tax)
label define q5_tax 1 "'250/month'" 0 "'3,000/year'"
label values q5smalldeno_tax q5_tax

gen condition4vs1=.
recode condition4vs1 (.=0) if taxincreasesplit==1
recode condition4vs1 (.=1) if taxincreasesplit==4

*** A "manipulation check" - did the respondents remember number of youths correctly***
recode  q8a (4=1) (1 2 3 5=0), gen(q8acorrect)
recode  q8b (4=1) (1 2 3 5=0), gen(q8bcorrect)
recode  q8c (3=1) (1 2 4 5=0), gen(q8ccorrect)
recode  q8d (3=1) (1 2 4 5=0), gen(q8dcorrect)
gen q8correct=max(q8acorrect, q8bcorrect, q8ccorrect, q8dcorrect)
tab1 q8acorrect q8bcorrect q8ccorrect q8dcorrect q8correct

***check for missing values on relevant variables***
gen missingvariable=0
recode missingvariable (0=1)if q5largedeno_people==.|q5smalldeno_tax==.|LR_with_party_median==.|numeracy==.

******************************************************************************************
***ANALYSIS*******************************************************************************
******************************************************************************************

***descriptives***
tab female if taxincreasesplit!=.
sum age if taxincreasesplit!=.
tab age_group if taxincreasesplit!=.
tab red if taxincreasesplit!=.
tab blue if taxincreasesplit!=.
tab education_category if taxincreasesplit!=.

***balance across conditions (required by reviewer!)***
mlogit taxincreasesplit i.gender age i.red i.education_cate 
tab female taxincreasesplit, chi
reg age i.taxincreasesplit
tab red taxincreasesplit,chi
tab blue if taxincreasesplit!=.
tab education_cate taxincreasesplit, chi


*************************************************************************************************************************************************************************
*Models with the four experimental groups as variables***
*************************************************************************************************************************************************************************

***SIMPLE MODEL***
tab taxincrease taxincreasesplit, col chi V /*for use in text and table 1*/
logit taxincrease i.taxincreasesplit
margins, over(taxincreasesplit)
pwcompare i.taxincrease, effects groups cformat(%9.2f) pformat(%5.4f)
prtest taxincrease, by(condition4vs1)


*************************************************************************************************************************************************************************
*Models with the two factors (factorial models) as variables
*************************************************************************************************************************************************************************

***SIMPLE FACTORIAL MODEL***
logit taxincrease i.q5largedeno_people i.q5smalldeno_tax
eststo factor_simple
margins i.q5largedeno_people i.q5smalldeno_tax
margins, dydx(q5largedeno_people q5smalldeno_tax)
testnl (_b[1.q5largedeno_people]=_b[1.q5smalldeno_tax])

***FACTORIAL MODEL WITH 2-WAY INTERACTIONS***
logit taxincrease i.q5largedeno_people i.q5smalldeno_tax numeracy LR_with_party_median i.q5largedeno_people#c.numeracy i.q5smalldeno_tax#c.numeracy i.q5largedeno_people#c.LR_with_party_median i.q5smalldeno_tax#c.LR_with_party_median
estimates store factor_interactions_cont

	/*diagnostics (deactivated because it takes a long time to execute)
	linktest //linktest does not suggest any specification error
	boxtid logit 	taxincrease i.q5largedeno_people q5smalldeno_tax c.numeracy c.LR_with_party_median /// Box-Tidwell test does not show significant improvements by changing powers of variables(but multicollinearity)
								i.q5largedeno_people#c.numeracy i.q5smalldeno_tax#c.numeracy ///
								i.q5largedeno_people#c.LR_with_party_median i.q5smalldeno_tax#c.LR_with_party_median ///
								c.numeracy#c.LR_with_party_median, ltolerance(0.000001)  
	boxtid logit 	taxincrease i.q5largedeno_people c.numeracy c.LR_with_party_median /// Box-Tidwell test does not show significant improvements by changing powers of variables 
								i.q5largedeno_people#c.numeracy ///
								i.q5largedeno_people#c.LR_with_party_median ///
								c.numeracy#c.LR_with_party_median, ltolerance(0.000001) 
	boxtid logit 	taxincrease i.q5smalldeno_tax c.numeracy c.LR_with_party_median /// Box-Tidwell test does not show significant improvements by changing powers of variables 
								i.q5smalldeno_tax#c.numeracy ///
								i.q5smalldeno_tax#c.LR_with_party_median ///
								c.numeracy#c.LR_with_party_median, ltolerance(0.000001)	

	*/

*Numeracy*
sum numeracy, detail //mean-sd=.2423944 and mean+sd=7527424 

estimates restore factor_interactions_cont
margins, dydx(q5largedeno_people) at(numeracy=(0(.1)1))                    //significant effects for all  but the most numerate respondents
margins, dydx(q5largedeno_people) at(numeracy=(.2423944 .7527424)) //significant effects for low but not high numeracy (numeracy set at mean-sd and mean+sd)
margins, dydx(q5largedeno_people) at(numeracy=(.2423944 .7527424)) pwcompare(effects) //differences in effects are not significantly different for low vs. high numeracy (numeracy set at mean-sd and mean+sd)
margins, dydx(q5largedeno_people) at(numeracy=(0 1)) pwcompare(effects) //differences in effects are not significantly different for low vs. high numeracy (numeracy set at extreme levels)

	*CHECKS*
	margins, dydx(q5largedeno_people) at(numeracy=(0(.1)1)) post coeflegend 
	lincom _b[1.q5largedeno_people:1bn._at]- _b[1.q5largedeno_people:11._at]   //results consistent with margins, pwcompare(effects)
	
estimates restore factor_interactions_cont
margins, dydx(q5smalldeno_tax) at(numeracy=(0(.1)1))                       //non-significant effects for both low and high numeracy
margins, dydx(q5smalldeno_tax) at(numeracy=(0(.1)1)) pwcompare(effects)    //differences in effects are not significantly different for low vs. high numeracy

*Political Predisposition*
sum LR_with_party_median, detail //mean-sd=3201983 and mean+sd=.8876003

estimates restore factor_interactions_cont 
margins, at(LR_with_party_median=(0(.1)1))  //note: LR has large main effect (64.1% on far left, 17,6% on far right)
margins, at(LR_with_party_median=(.3201983 .8876003))  //note: also large difference between moderately left and moderately right
margins, dydx(q5largedeno_people) at(LR_with_party_median=(0(.01)1))                      //significant effects for all but the most rightwing
margins, dydx(q5largedeno_people) at(LR_with_party_median=(.85(.001).87))  //: effect of youth framing for values below .86
margins, dydx(q5largedeno_people) at(LR_with_party_median=(.3201983 .8876003)) //significant effects for left but not right (left and right set at mean-sd and mean+sd)
margins, dydx(q5largedeno_people) at(LR_with_party_median=(.3201983 .8876003)) pwcompare(effects) //differences in effects are not significantly different for left vs. right (left and right set at mean-sd and mean+sd)
margins, dydx(q5largedeno_people) at(LR_with_party_median=(0 1)) pwcompare(effects)    //differences in effects are not significantly different for left and right (left and right set at extreme levels)
	*CHECKS*
	margins, dydx(q5largedeno_people) at(LR_with_party_median=(0(.1)1)) post coeflegend
	lincom _b[1.q5largedeno_people:1bn._at]-_b[1.q5largedeno_people:11._at]					//results consistent with margins, pwcompare(effects)

estimates restore factor_interactions_cont
margins, dydx(q5smalldeno_tax) at(LR_with_party_median=(0(.01)1))                          //significant effects for some respondents center
margins, dydx(q5smalldeno_tax) at(LR_with_party_median=(0(.1)1)) pwcompare(effects)       //differences in effects are not significantly different for Left, Center and Right


***FACTORIAL MODEL WITH 3-WAY INTERACTIONS***
logit taxincrease i.q5largedeno_people##c.numeracy##c.LR_with_party_median i.q5smalldeno_tax##c.numeracy##c.LR_with_party_median
estimates store factor_3interactions_cont

	/*diagnostics (deactivated because it takes a long time to execute)
	linktest //linktest does not suggest any specification error
	boxtid logit 	taxincrease i.q5largedeno_people q5smalldeno_tax c.numeracy c.LR_with_party_median /// Box-Tidwell test does not show significant improvements by changing powers of variables(but multicollinearity)
								i.q5largedeno_people#c.numeracy i.q5smalldeno_tax#c.numeracy ///
								i.q5largedeno_people#c.LR_with_party_median i.q5smalldeno_tax#c.LR_with_party_median ///
								c.numeracy#c.LR_with_party_median ///			
								i.q5smalldeno_tax#c.numeracy#c.LR_with_party_median ///
								i.q5largedeno_people#c.numeracy#c.LR_with_party_median, ltolerance(0.000001)  
	boxtid logit 	taxincrease i.q5largedeno_people c.numeracy c.LR_with_party_median /// Box-Tidwell test does not show significant improvements by changing powers of variables 
								i.q5largedeno_people#c.numeracy ///
								i.q5largedeno_people#c.LR_with_party_median ///
								c.numeracy#c.LR_with_party_median ///			
								i.q5largedeno_people#c.numeracy#c.LR_with_party_median, ltolerance(0.000001) 
	boxtid logit 	taxincrease i.q5smalldeno_tax c.numeracy c.LR_with_party_median /// Box-Tidwell test does not show significant improvements by changing powers of variables 
								i.q5smalldeno_tax#c.numeracy ///
								i.q5smalldeno_tax#c.LR_with_party_median ///
								c.numeracy#c.LR_with_party_median ///			
								i.q5smalldeno_tax#c.numeracy#c.LR_with_party_median, ltolerance(0.000001)	
	*/					


		
*Probing interaction with Youth Ratio
	estimates restore factor_3interactions_cont
	margins, over(q5largedeno_people) at(numeracy=(0 1) LR_with_party_median=(0) ) pwcompare(effects)
	margins, over(q5largedeno_people) at(numeracy=(0 1) LR_with_party_median=(.3201983) ) pwcompare(effects)
	margins, over(q5largedeno_people) at(numeracy=(0 1) LR_with_party_median=(.8876003 ) ) pwcompare(effects)
	margins, over(q5largedeno_people) at(numeracy=(0 1) LR_with_party_median=(1) ) pwcompare(effects)
	margins, over(q5largedeno_people) at(numeracy=(.2423944 .7527424) LR_with_party_median=(0) ) pwcompare(effects)
	margins, over(q5largedeno_people) at(numeracy=(.2423944 .7527424) LR_with_party_median=(.3201983) ) pwcompare(effects)
		//highly numerate leftleaners are more likely (p=.03) to choose Scenario B than low numerate leftwingers (used in paper)
	margins, over(q5largedeno_people) at(numeracy=(.2423944 .7527424) LR_with_party_median=(.8876003 ) ) pwcompare(effects)
		//However, highly numerate rightleaners are also more likely (nonsignificantly) to choose Scenario B than low numerate rightwingers (used in paper)
	margins, over(q5largedeno_people) at(numeracy=(.2423944 .7527424) LR_with_party_median=(1) ) pwcompare(effects)

	estimates restore factor_3interactions_cont
	margins, over(q5largedeno_people) at(numeracy=(.2423944 .7527424) LR_with_party_median=(.32019831 .8876003) ) 
	margins,  at(q5largedeno_people=0 numeracy=(.7527424) LR_with_party_median=(.32019831 .8876003) ) pwcompare(effects)
		//difference between highly numerate left and right is 26.3%
	margins,  at(q5largedeno_people=0 numeracy=(.2423944) LR_with_party_median=(.32019831 .8876003) ) pwcompare(effects)
		//difference between low numerate left and right is 18.9%
	estimates restore factor_3interactions_cont
		margins if q5largedeno_people==0,at(LR_with_party_median=(.3201983 .8876003 ) numeracy=(.2423944 .7527424)) post coeflegend
		lincom _b[1bn._at]-_b[2._at]
		lincom _b[3._at]-_b[4._at]
		lincom (_b[1bn._at]-_b[2._at])-(_b[3._at]-_b[4._at])
		//the difference between effects (26.3% and 18.9%) is not significant (p=.34)
	estimates restore factor_3interactions_cont
		margins if q5largedeno_people==1,at(LR_with_party_median=(.3201983 .8876003 ) numeracy=(.2423944 .7527424)) post coeflegend
		lincom _b[1bn._at]-_b[2._at]
		lincom _b[3._at]-_b[4._at]
		lincom (_b[1bn._at]-_b[2._at])-(_b[3._at]-_b[4._at])
		//the difference between effects (28.9% and 32.0%) is not significant (p=.70)

	
*Probing 3-way interaction with Tax Ratio
	estimates restore factor_3interactions_cont
	margins, over(q5smalldeno_tax) at(numeracy=(0 1) LR_with_party_median=(0) ) pwcompare(effects)
	margins, over(q5smalldeno_tax) at(numeracy=(0 1) LR_with_party_median=(.3201983) ) pwcompare(effects)
	margins, over(q5smalldeno_tax) at(numeracy=(0 1) LR_with_party_median=(.8876003 ) ) pwcompare(effects)
	margins, over(q5smalldeno_tax) at(numeracy=(0 1) LR_with_party_median=(1) ) pwcompare(effects)
	margins, over(q5smalldeno_tax) at(numeracy=(.2423944 .7527424) LR_with_party_median=(0) ) pwcompare(effects)
	margins, over(q5smalldeno_tax) at(numeracy=(.2423944 .7527424) LR_with_party_median=(.3201983) ) pwcompare(effects)
		//no significant difference between highly numerate and low numerate leftleaners 
	margins, over(q5largedeno_people) at(numeracy=(.2423944 .7527424) LR_with_party_median=(.8876003 ) ) pwcompare(effects)
		//no significant difference between highly numerate and low numerate rightleaners
	margins, over(q5smalldeno_tax) at(numeracy=(.2423944 .7527424) LR_with_party_median=(1) ) pwcompare(effects)
	
	estimates restore factor_3interactions_cont
	margins, over(q5smalldeno_tax) at(numeracy=(.2423944 .7527424) LR_with_party_median=(.32019831 .8876003) ) 
	margins,  at(q5smalldeno_tax=0 numeracy=(.7527424) LR_with_party_median=(.32019831 .8876003) ) pwcompare(effects)
		//difference between highly numerate left and right is 33.5%
	margins,  at(q5smalldeno_tax=0 numeracy=(.2423944) LR_with_party_median=(.32019831 .8876003) ) pwcompare(effects)
		//difference between low numerate left and right is 20.4%
	estimates restore factor_3interactions_cont
		margins if q5smalldeno_tax==0,at(LR_with_party_median=(.3201983 .8876003 ) numeracy=(.2423944 .7527424)) post coeflegend
		lincom _b[1bn._at]-_b[2._at]
		lincom _b[3._at]-_b[4._at]
		lincom (_b[1bn._at]-_b[2._at])-(_b[3._at]-_b[4._at])
		//the difference between effects (20.4% and 33.5%) is not significant (p=.12)
	estimates restore factor_3interactions_cont
		margins if q5smalldeno_tax==1,at(LR_with_party_median=(.3201983 .8876003 ) numeracy=(.2423944 .7527424)) post coeflegend
		lincom _b[1bn._at]-_b[2._at]
		lincom _b[3._at]-_b[4._at]
		lincom (_b[1bn._at]-_b[2._at])-(_b[3._at]-_b[4._at])
		//the difference between effects (27.4% and 24.9%) is not significant (p=.76)

	
//Overall - Across all conditions 
		estimates restore factor_3interactions_cont
		margins ,at(LR_with_party_median=(.3201983 .8876003 ) numeracy=(.2423944 .7527424)) post coeflegend
		lincom _b[1bn._at]-_b[2._at]
		lincom _b[3._at]-_b[4._at]
		lincom (_b[1bn._at]-_b[2._at])-(_b[3._at]-_b[4._at])
		//Overall, the left-right difference is larger among highly numerate (29.2%) than among low numerate (23.9%), but not signficantly (p=.35)


************************************************************************************************************************************************************************
*Tables and figures for paper
************************************************************************************************************************************************************************

   
***Regression table***	   
esttab factor_simple factor_interactions_cont factor_3interactions_cont using table2.rtf, b(2) se(2) pr2(2)  compress scalars(chi2 p)replace ///
	   star(* 0.05 ** 0.01 *** 0.001)  stardetach title("Table x: Logit models") mtitles("Model 1" "Model 2" "Model 3") nonumbers ///
	   drop(0.* ) order(1.q5largedeno_people 1.q5smalldeno_tax numeracy 1.q5largedeno_people#c.numeracy 1.q5smalldeno_tax#c.numeracy ///
	   LR_with_party_median 1.q5largedeno_people#c.LR_with_party_median 1.q5smalldeno_tax#c.LR_with_party_median c.numeracy#c.LR_with_party_median ///
	   1.q5largedeno_people#c.numeracy#c.LR_with_party_median 1.q5smalldeno_tax#c.numeracy#c.LR_with_party_median) /// 
	   coeflabels( 1.q5largedeno_people "   Large youth ratio" 1.q5smalldeno_tax "   Small tax ratio" numeracy "Numeracy" ///
	   1.q5largedeno_people#c.numeracy "   Large youth ratio X Numeracy" 1.q5smalldeno_tax#c.numeracy "   Small tax ratio X Numeracy" ///
	   LR_with_party_median "Left-Right Position" 1.q5largedeno_people#c.LR_with_party_median "   Large youth ratio X Left-Right" 1.q5smalldeno_tax#c.LR_with_party_median "   Small tax ratio X Left-Right" ///
	   c.numeracy#c.LR_with_party_median "Numeracy X Left-Right" ///
	   1.q5largedeno_people#c.numeracy#c.LR_with_party_median "Large youth ratio X Numeracy X Left-Right" ///
	   1.q5smalldeno_tax#c.numeracy#c.LR_with_party_median "Small tax ratio X Numeracy X Left-Right" ///
	  _cons "Constant") ///
		note("Notes: Logistic regression coefficients (and standard errors)")
	 
	 
*************	   
***Figures***
*************

***FIGURE 1: NUMERACY***
estimates restore factor_interactions_cont
margins, dydx(q5largedeno_people) at(numeracy=(0(.025)1))
marginsplot, title("Numeracy and the Effect of the Youth Ratio", size(medium)) subtitle(, size(small)box fcolor(none)) ///
			 recast(scatter) recastci(rspike) ytitle("Effects on Pr(Choosing Scenario B)", size(small) margin(0 1 0 0)) ylabel(.0(.1)0.4, grid gmin gmax) xtitle("Numeracy") ///
			 xlabel(0(.1)1, labsize(small)) xscale(range(0 1)) scheme(s1mono) plotregion(lcolor(none)) ///
			 yline(0, lwidth(medium) lcolor(gs10) extend) //addplot(kdensity numeracy, area(.1) lpattern(dash) legend(off) xtitle("Numeracy"))
graph save Numeracy_people, replace
graph export Numeracy_people.emf, replace

estimates restore factor_interactions_cont
margins ,dydx(q5smalldeno_tax) at(numeracy=(0(.025)1))
marginsplot, title("Numeracy and the Effect of the Tax Ratio", size(medium)) subtitle(, size(small)box fcolor(none)) ///
			 recast(scatter) recastci(rspike) ytitle("Effects on Pr(Choosing Scenario B)", size(small) margin(0 1 0 0)) ylabel(.0(.1)0.4, grid gmin gmax) xtitle("Numeracy") ///
			 xlabel(0(.1)1, labsize(small)) xscale(range(0 1)) scheme(s1mono) plotregion(lcolor(none)) ///
			 yline(0, lwidth(medium) lcolor(gs10) extend) //addplot(kdensity numeracy, area(.1) lpattern(dash) legend(off) xtitle("Numeracy"))
graph save Numeracy_tax, replace
graph export Numeracy_tax.emf, replace

graph combine "Numeracy_people" "Numeracy_tax" , c(1) iscale(.7) imargin(bottom) plotregion(margin(zero)) graphregion(lcolor(black) fcolor(none)) xsize(4) ysize(4) ///
			  caption("{bf:Figure 1.} Numeracy as a Moderator (with 95% CI). The graphs illustrate the average" ///
			  "marginal effect of experimental conditions, contingent on the respondent's level of" ///
			  "numeracy.", size(small))
graph export Numeracy_all.emf, replace 
graph export Figure1.tif, width(2000) replace

***FIGURE 2: LEFT-RIGHT***
estimates restore factor_interactions_cont
margins ,at(LR_with_party_median=(0(.025)1))
marginsplot, title("Main Effect of Political Predisposition (Including lowess-line)", size(medium)) subtitle(, size(small)box fcolor(none)) ///
             recast(scatter) recastci(rspike) ytitle("Pr(Choosing Scenario B)", size(small) margin(0 1 0 0)) ylabel(.0(.1)0.7, grid gmin gmax) xtitle("Left to Right") ///
			 xlabel(0(.1)1, labsize(small)) xscale(range(0 1)) scheme(s1mono) plotregion(lcolor(none)) ///
			 yline(0, lwidth(medthick) lcolor(gs10) extend) ///
			 addplot((lowess taxincrease LR_with_party_median if taxincreasesplit!=., lpattern(dot) lwidth(thick) legend(off)), below) ///
			 xlabel(#10)
graph save LR_main, replace 
graph export LR_main.emf, replace
	
estimates restore factor_interactions_cont
margins ,dydx(q5largedeno_people) at(LR_with_party_median=(0(.025)1))
marginsplot, title("Political Predisposition and the Effect of the Youth Ratio", size(medium)) subtitle(, size(small)box fcolor(none)) ///
             recast(scatter) recastci(rspike) ytitle("Effects on Pr(Choosing Scenario B)", size(small) margin(0 1 0 0)) ylabel(.0(.1)0.4, grid gmin gmax) xtitle("Left to Right") ///
			 xlabel(0(.1)1, labsize(small)) xscale(range(0 1)) scheme(s1mono) plotregion(lcolor(none)) ///
			 yline(0, lwidth(medthick) lcolor(gs10) extend) //addplot(kdensity LR_with_party_mean, area(.1) lpattern(dash) legend(off) xlabel(0(.1)1) ylabel(.0(.1)0.4)) 
graph save LR_people, replace
graph export LR_people.emf, replace
			  
estimates restore factor_interactions_cont
margins ,dydx(q5smalldeno_tax) at(LR_with_party_median=(0(.025)1))
marginsplot, title("Political Predisposition and the Effect of the Tax Ratio", size(medium)) subtitle(, size(small)box fcolor(none)) ///
             recast(scatter) recastci(rspike) ytitle("Effects on Pr(Choosing Scenario B)", size(small) margin(0 1 0 0)) ylabel(.0(.1)0.4, grid gmin gmax) xtitle("Left to Right") ///
			 xlabel(0(.1)1, labsize(small)) xscale(range(0 1)) scheme(s1mono) plotregion(lcolor(none)) ///
			 yline(0, lwidth(medthick) lcolor(gs10) extend) //addplot(kdensity LR_with_party_mean, area(.1) lpattern(dash) legend(off) xlabel(0(.1)1) ylabel(.0(.1)0.4)) 
graph save LR_tax, replace		
graph export LR_tax.emf, replace

			  
graph combine "LR_main" "LR_people" "LR_tax" , c(1) iscale(.7) imargin(bottom) plotregion(margin(zero)) graphregion(lcolor(black) fcolor(none)) xsize(5) ysize(6) ///
			  caption("{bf:Figure 2.} Political Predisposition as Main Effect and Moderator (with 95% CI)." ///
			  "The graphs illustrate the probability of choosing Scenario B (scenario with tax" ///
			  "increase), contingent on the respondent's political predisposition and" ///
			  "experimental condition.", size(small))
graph export LR_all.emf, replace 
graph export Figure2.tif, width(2000) replace	

***FIGURE 3: COMBINED EFFECTS OF NUMERACY AND LEFT-RIGHT*

estimates restore factor_3interactions_cont
margins, at(q5largedeno_people=0 numeracy=(0(.025)1) LR_with_party_median=(.3201983 .8876003 ))
marginsplot, title("Youth Ratio: '7/100'", size(medium) ) ///
			recast(scatter) plotopts(msize(small)mcolor(black)) plot2opts(msymbol(lgx)) recastci(rspike) ytitle("Pr(Choosing Scenario B)", size(small) margin(0 1 0 0)) ylabel(.0(.1)0.7, grid gmin ) xtitle("Numeracy") ///
			 xlabel(0(.1)1, labsize(small)) xscale(range(0 1)) scheme(s1mono) plotregion(lcolor(none)) legend(off) fxsize(100) fysize(100)   ///
			 yline(0, lwidth(medium) lcolor(gs10) extend)  
graph save numeracy_LR_people_smallratio, replace

estimates restore factor_3interactions_cont
margins, at(q5largedeno_people=1 numeracy=(0(.025)1) LR_with_party_median=(.3201983 .8876003 ))
marginsplot, title("Youth Ratio: '4,900/70,000'", size(medium)) ///
			recast(scatter) plotopts(msize(small)mcolor(black)) plot2opts(msymbol(lgx)) recastci(rspike) ytitle("Pr(Choosing Scenario B)", size(small) margin(0 1 0 0)) ylabel(.0(.1)0.7, grid gmin ) xtitle("Numeracy") yscale(off) ///
			 xlabel(0(.1)1, labsize(small)) xscale(range(0 1)) scheme(s1mono) plotregion(lcolor(none))  legend(off) fxsize(100) fysize(100) ///
			 yline(0, lwidth(medium) lcolor(gs10) extend) 
graph save numeracy_LR_people_largeratio, replace
			 
			 
estimates restore factor_3interactions_cont
margins, at(q5smalldeno_tax=0 numeracy=(0(.025)1) LR_with_party_median=(.3201983 .8876003 ))
marginsplot, title("Tax ratio: '3000/year'", size(medium)) ///
			recast(scatter) plotopts(msize(small)mcolor(black)) plot2opts(msymbol(lgx)) recastci(rspike) ytitle("Pr(Choosing Scenario B)", size(small) margin(0 1 0 0)) ylabel(.0(.1)0.7, grid gmin ) xtitle("Numeracy") ///
			 xlabel(0(.1)1, labsize(small)) xscale(range(0 1)) scheme(s1mono) plotregion(lcolor(none)) legend(off) fxsize(100) fysize(100) ///
			 yline(0, lwidth(medium) lcolor(gs10) extend) 
graph save numeracy_tax_largeratio, replace
			 
			 
estimates restore factor_3interactions_cont
margins, at(q5smalldeno_tax=1 numeracy=(0(.025)1) LR_with_party_median=(.3201983 .8876003 ))
marginsplot, title("Tax ratio: '250/month'", size(medium)) ///
			recast(scatter) plotopts(msize(small)mcolor(black)) plot2opts(msymbol(lgx)) recastci(rspike) ytitle("Pr(Choosing Scenario B)", size(small) margin(0 1 0 0)) ylabel(.0(.1)0.7, grid gmin ) xtitle("Numeracy") yscale(off) ///
			 xlabel(0(.1)1, labsize(small)) xscale(range(0 1)) scheme(s1mono) plotregion(lcolor(none)) legend(off) fxsize(100) fysize(100) ///
			 yline(0, lwidth(medium) lcolor(gs10) extend) 		
graph save numeracy_tax_smallratio, replace

graph combine "numeracy_LR_people_smallratio" "numeracy_LR_people_largeratio" "numeracy_tax_largeratio" "numeracy_tax_smallratio" , ///
				c(2) iscale(.6) imargin(medsmall) plotregion(margin(zero)) graphregion(lcolor(black) fcolor(none)) xsize(5) ysize(6) ycommon ///
			note("{&bull}  Leftwing voter (1 SD to the left of the mean)" "{stSans:x}  Rigthwing voter (1 SD to the right of the mean)", justification(left) position(6) span box fcolor(bg) lwidth(vvthin) size(small) ) ///
			caption(" " ///
			"{bf:Figure 3.} The Joint effects of numeracy and political predisposition (with 95% CI)." ///
			  "The graphs illustrate the probability of choosing Scenario B (scenario with tax" ///
			  "increase), contingent on respondent's numeracy, political predisposition and" ///
		  	  "experimental condition.", size(small)) 
graph save figure3, replace		
graph export Figure3.tif, width(2000) replace	
			 
*******************************************************************************************************************************************************
*Robustness check 
*******************************************************************************************************************************************************

*using a measure of numeracy that is based on non-squared values*
* use: numeracy_unstandardized
